﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Tree.Test
{
    [TestClass]
    public class NodeTest
    {
        [TestMethod]
        public void AddNodeTest()
        {
            Node<int> intNode1 = new Node<int>();
            intNode1.Value = 1;
            Node<int> intNode2 = new Node<int>();
            intNode2.Value = 2;
            Node<int> intNode3 = new Node<int>();
            intNode3.Value = 3;

            intNode1.AddChild(intNode2);
            intNode1.AddChild(intNode3);

            Assert.AreEqual(2, intNode1.Childs[0].Value);
            Assert.AreEqual(3, intNode1.Childs[1].Value);
        }

        [TestMethod]
        public void RemoveChildTest1()
        {
            Node<int> intNode1 = new Node<int>();
            intNode1.Value = 1;
            Node<int> intNode2 = new Node<int>();
            intNode2.Value = 2;
            Node<int> intNode3 = new Node<int>();
            intNode3.Value = 3;
            intNode1.Childs.Add(intNode2);
            intNode1.Childs.Add(intNode3);

            intNode1.RemoveChild(intNode2);

            Assert.IsFalse(intNode1.Childs.Contains(intNode2));

        }

        [ExpectedException(typeof(InvalidOperationException))]
        [TestMethod]
        public void RemoveChildTest2()
        {
            Node<int> intNode1 = new Node<int>();
            intNode1.Value = 1;
            Node<int> intNode2 = new Node<int>();
            intNode2.Value = 2;
            Node<int> intNode3 = new Node<int>();
            intNode3.Value = 3;
            intNode1.Childs.Add(intNode3);

            intNode1.RemoveChild(intNode2);
        }

    }
}
